# @Time : 2020/11/24 下午4:26 

# @Author : tanqing

# @File : random_str.py 

# @Software: PyCharm

# 字符串重复统计
# 字符串'abcdefghijklmnopqrstuvwxyz'
# 随机挑选2个字母组成字符串，共挑选100个
# 降序输出所有不同的字符串及重复的次数

import random

s='abcdefghijklmnopqrstuvwxyz'
s_list=[]

# 生成100个字符串
for i in range(100):
    s_tmp=random.choices(s,k=2)
    s_list.append(s_tmp[0]+s_tmp[1])

# 统计每个字符串的次数
s_count={}
for i in range(100):
    s_num=0
    for n in range(100):
        if s_list[i]==s_list[n]:
            s_num+=1
    s_count[s_list[i]]=s_num

s_temp={}
for k,v in s_count.items():
    s_temp.setdefault(v,[])
    s_temp[v].append(k)

result=[]
for i in sorted(s_temp,reverse=True):
    for n in s_temp[i]:
        result.append((n,i))
print(result)


# 做得不错
